<?php
// if(isset($_COOKIE['name'])){
//                $name1=$_COOKIE['name'];
//            }else{
//                $name1='';
//                exit('不允许操作');
//            }
session_start();
if (isset($_SESSION['name'])) {
    $name1 = $_SESSION['name'];
} else {
    $name1 = '';
    exit('不允许操作');
}

define('HOST', 'localhost');
define('USER', 'mes');
define('PASSWORD', '111111');
define('DATABASE', 'mes');

$conn = mysqli_connect(HOST, USER, PASSWORD, DATABASE)or die('数据库连接失败' . mysqli_connect_error());

function test_input($data){
    $data= trim($data);
    $data= stripcslashes($data);
    $data= htmlspecialchars($data);
    return $data;
}

$mes = $_REQUEST['mes'];
$time = time();
//$name = $_COOKIE['name'];
$name=$name1;
$sql = "insert into liuyan(content,time,username)values('$mes','$time','$name')";
$res = mysqli_query($conn, $sql);
if (mysqli_affected_rows($conn) != 1) {
    echo '<script>alert("发表失败！");window.location="liuyan0.php"</script>';
} else {
    echo '<script>alert("发表成功！");window.location="liuyan0.php"</script>';
}